<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>练习1：给表格的奇偶行添加不同的背景色</title>
    <style>
        table{
            border-collapse: collapse;
        }
        td,th{
            width: 100px;
            height: 20px;
            border: 1px solid #cccccc;
        }
    </style>
</head>
<body>
    <button id="light">浅色样式</button>
    <button id="dark">深色样式</button>
    <br><br>
    <table id="list">
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </table>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <script>
        //浅色按钮点击事件
        $('#light').click(function(){
            $('#list tr:even').css('background','lightblue')
            $('#list tr:odd').css('background','lightgreen')
        })
        //深色按钮点击事件
        $('#dark').click(function(){
            $('#list tr:nth-child(even)').css('background','blue')
            $('#list tr:nth-child(odd)').css('background','green')
        })
    </script>
</body>
</html>